package com.ruoyi.operator.service.impl;


import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.operator.mapper.OptShopClerkMapper;
import com.ruoyi.operator.service.IOptShopClerkService;
import com.ruoyi.system.domain.SysUserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 店员 业务层处理
 *
 * @author ruoyi
 */
@Service
public class OptShopClerkServiceImpl implements IOptShopClerkService
{
    @Autowired
    private OptShopClerkMapper shopClerkMapper;

    /**
     * 根据条件分页查询员工列表
     *
     * @param user 员工信息
     * @return 员工信息集合信息
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<SysUser> selectClerkList(SysUser user)
    {
        return shopClerkMapper.selectClerkList(user);
    }


    /**
     * 校验手机号码是否唯一
     *
     * @param user 用户信息
     * @return
     */
    @Override
    public String checkPhoneUnique(SysUser user)
    {
        Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
        SysUser currentUser = ShiroUtils.getSysUser();
        user.setDeptId(currentUser.getDeptId());
        SysUser info = shopClerkMapper.checkPhoneUnique(user);
        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
        {
            return UserConstants.USER_PHONE_NOT_UNIQUE;
        }
        return UserConstants.USER_PHONE_UNIQUE;
    }


    /**
     * 校验员工是否允许操作
     *
     * @param user 员工信息
     */
    @Override
    public void checkUserAllowed(SysUser user) {

    }


}
